package com.swing.obj;

import com.swing.event.KeyInput;

import java.awt.*;
import java.awt.event.KeyEvent;

public class Rect extends GameObject {
    
    private float x;
    private float y;
    private float w;
    private float h;

    public Rect(float x, float y, float w, float h) {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
    }

    @Override
    public void update(float deltaTime) {
        if (KeyInput.isPressed(KeyEvent.VK_A)) {
            x -= 200 * deltaTime;
        }
        if (KeyInput.isPressed(KeyEvent.VK_D)) {
            x += 200 * deltaTime;
        }
        if (KeyInput.isPressed(KeyEvent.VK_W)) {
            y -= 200 * deltaTime;
        }
        if (KeyInput.isPressed(KeyEvent.VK_S)) {
            y += 200 * deltaTime;
        }
    }

    @Override
    public void render(Graphics g) {
        // 设置当前绘图颜色为深灰色
        g.setColor(Color.DARK_GRAY);
        g.fillRect((int) x, (int) y, (int)w, (int)h);
    }
}
